package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "品牌管理")
@RequestMapping("/admin/system/brand")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @GetMapping("/findAll")
    @Operation(summary = "查询所有品牌")
    public Result<List<Brand>> findAll(){
        List<Brand> list=brandService.finAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分页查询品牌")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable("page")Integer page, @PathVariable("limit") Integer limit){
        PageInfo<Brand> pageInfo=brandService.findByPage(page,limit);
        return Result.ok(pageInfo);
    }

    @Operation(summary = "保存品牌")
    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.ok(null);
    }

    @Operation(summary = "修改品牌")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.ok(null);
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/deleteById/{id}")
    public Result DeleteBrandById(@PathVariable Integer id){
        brandService.DeleteBrandById(id);
        return Result.ok(null);
    }

}
